<?php require_once VIEWPATH . 'common/header.php'; ?>
<link rel="stylesheet" type="text/css" href="<?= STATICURL; ?>h-ui/css/page.css" />
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 账目管理 <span class="c-gray en">&gt;</span> 账目列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <button onclick="removeIframe()" class="btn btn-primary radius">关闭选项卡</button>
	  日期范围：
        <input  type="text" value="<?= $starttime ?? ''?>" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}' })" id="logmin" class="input-text Wdate starttime" style="width:120px;">
        <input type="text"  value="<?= $endtime ?? ''?>"  onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d' })" id="logmax" class="input-text Wdate endtime" style="width:120px;">
        <input type="text" name="" value="<?=$keyword ?? ''?>" id="keyword" placeholder=" 账目名称" style="width:250px" class="input-text">
        <span name="" id="J_search" class="btn btn-success"><i class="Hui-iconfont">&#xe665;</i> 搜账目</span>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a class="btn btn-primary radius" data-title="添加账目" data-href="article-add.html"
               onclick="article_add('添加账目','/bill/addview')"><i class="Hui-iconfont">&#xe600;</i> 添加账目</a>
        </span>
        <span class="r">共有数据：<strong><?=$total_rows?></strong> 条</span></div>
    <div class="mt-20">
        <table id="process" class="table table-border table-bordered table-bg table-hover  table-responsive">
            <thead>
            <tr class="text-c">
                <th class="sorting_desc" width="100">合同号</th>
                <th width="80">金额</th>
                <th width="120">客户单位</th>
                <th width="120">签订时间</th>
                <th width="120">实际发货时间</th>
                <th width="120">件号</th>
                <th width="130">名称</th>
                <th width="80">数量</th>
                <th width="80">销售单价</th>
                <th width="80">销售总价</th>
                <th width="80">采购单价</th>
                <th width="80">采购总价</th>
                <th width="120">供应商</th>
                <th width="120">联系</th>
                <th width="80">采购总费用</th>
                <th width="80">利润</th>
                <th width="50">订单来源</th>
                <th width="120" class="sorting_disabled">操作</th>
            </tr>
            </thead>
            <tbody>
            <?php if($billList):?>
            <?php foreach ($billList as $row): ?>
                <tr class="text-c"  data-id = "<?=$row['bill_id']?>">
                    <td contract_number="<?= $row['contract_number'] ?>" class="text-l">
                        <a style="text-decoration:none" class="ml-5" onClick="article_detail('订单详情','/bill/detail?contract_number=<?= $row['contract_number'] ?>')" href="javascript:;" title="查看详情"><?= $row['contract_number'] ?></a>
                        <br/>
                        <?php if($row['type'] == 1):?>
                            <a style="text-decoration:none" class="ml-5" onClick="article_edit('账单添加','/bill/addview?contract_number=<?=$row['contract_number']?>')" href="javascript:;" title="继续添加账目"><i class="icon Hui-iconfont">&#xe600;</i></a>
                        <?php endif;?>
                    </td>
                    <td contract_number="<?= $row['contract_number'] ?>"><?= $row['money']?></td>
                    <td contract_number="<?= $row['contract_number'] ?>"><?= $row['customer_unit'] ?></td>
                    <td contract_number="<?= $row['contract_number'] ?>"><?= date('Y/m/d', strtotime($row['signed_time'])) ?></td>
                    <td contract_number="<?= $row['contract_number'] ?>">
                        <?php if(strtotime($row['deliver_time']) > 0):?>
                            <?=date('Y/m/d', strtotime($row['deliver_time']))?>
                        <?php else:?>
                            <a class="label label-warning radius" style="text-decoration:none" onClick="deliver_goods(this,'<?= $row['contract_number']?>')" href="javascript:;" title="发货">发货</a>
                        <?php endif;?>
                    </td>
                    <td><?= $row['piece_number'] ?></td>
                    <td><?= $row['name'] ?></td>
                    <td><?= $row['number'] ?></td>
                    <td><?= $row['unit_selling_price'] ?></td>
                    <td><?= $row['sales_price'] ?></td>
                    <td contract_number="<?= $row['contract_number'] ?>"><?= $row['purchase_price'] ?></td>
                    <td><?= $row['purchase_total_price'] ?></td>
                    <td><?= $row['provider'] ?></td>
                    <td><?= $row['contact'] ?></td>
                    <td contract_number="<?= $row['contract_number'] ?>"><?= $row['total_purchase_cost'] ?></td>
                    <td contract_number="<?= $row['contract_number'] ?>"><?= $row['profit'] ?></td>
                    <td><?php if ($row['origin'] == 1): ?>淘宝<?php elseif($row['origin'] == 2): ?>微店<?php else:?>微信<?php endif; ?></td>
                    <td class="f-14 td-manage">
                        <?php if($row['type'] == 1):?>
                        <a style="text-decoration:none" class="ml-5" onClick="article_edit('账单编辑','/bill/editview?bill_id=<?=$row['bill_id']?>')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                        <?php elseif($row['type'] == 2):?>
                        <a style="text-decoration:none" class="ml-5" onClick="article_edit('运费编辑','/bill/editview?bill_id=<?=$row['bill_id']?>')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                        <?php endif;?>
                        <a style="text-decoration:none" class="ml-5" onClick="article_del(this,<?= $row['bill_id'] ?>)" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                        <?php if($row['type'] == 1):?>
                            <a style="text-decoration:none" class="ml-5" onClick="article_edit('账单编辑','/bill/addexpressview?contract_number=<?=$row['contract_number']?>')" href="javascript:;" title="添加邮费"><i class="Hui-iconfont">&#xe604;</i></a>
                        <?php endif;?>
                    </td>
                </tr>
            <?php endforeach; ?>
            <?php else:?>
                <tr >
                    <td style="text-align: center" colspan="18">暂无数据</td>
                </tr>
            <?php endif;?>
            </tbody>
        </table>
        <div class="page_links"><?= $page_links?></div>
    </div>
</div>
<!--请在下方写此页面业务相关的脚本-->
<?php require_once VIEWPATH . 'common/footer.php'; ?>
<script type="text/javascript" src="<?= STATICURL; ?>lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<?= STATICURL; ?>lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="<?= STATICURL; ?>lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
        _w_table_rowspan("#process", 1);
        _w_table_rowspan("#process", 2);
        _w_table_rowspan("#process", 3);
        _w_table_rowspan("#process", 4);
        _w_table_rowspan("#process", 5);
        _w_table_rowspan("#process", 15);
        _w_table_rowspan("#process", 16);
    });
    function _w_table_rowspan(_w_table_id, _w_table_colnum) {
        _w_table_firsttd = "";
        _w_table_currenttd = "";
        _w_table_SpanNum = 0;
        _w_table_Obj = $(_w_table_id + " tr td:nth-child(" + _w_table_colnum + ")");
        _w_table_Obj.each(function (i) {
            if (i == 0) {
                _w_table_firsttd = $(this);
                _w_table_SpanNum = 1;
            } else {
                _w_table_currenttd = $(this);
                if (_w_table_firsttd.attr('contract_number') == _w_table_currenttd.attr('contract_number')) {
                    _w_table_SpanNum++;
                    _w_table_currenttd.hide(); //remove();
                    _w_table_firsttd.attr("rowSpan", _w_table_SpanNum);
                } else {
                    _w_table_firsttd = $(this);
                    _w_table_SpanNum = 1;
                }
            }
        });
    }


    $('.table-sort').dataTable({
        "aaSorting": [[1, "desc"]],//默认第几个排序
        "bStateSave": true,//状态保存
        "pading": false,
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable": false, "aTargets": [0, 8]}// 不参与排序的列
        ]
    });

    $(".J_contact_show").click(function(){
        var contact = $(this).attr('data-value');
        var id = $(this).parent().attr('data-id');
        layer.tips(contact, '.contact_'+id, {
            tips: [4, '#78BA32']
        });
    });
    $("#J_search").click(function () {
        var params ={
            'starttime':$(".starttime") . val(),
            'endtime':$(".endtime") . val(),
            'keyword':$("#keyword") . val(),
            'timelimit':$("#timelimit") . val()
        };
        location = "/bill/index?" + $.param(params);
    });
    /*资讯-添加*/
    function article_add(title, url, w, h) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }
    /*资讯-编辑*/
    function article_edit(title, url) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }
    function article_detail(title, url, contract_number) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }
    /*资讯-删除*/
    function article_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: '/bill/delete',
                data: {bill_id: id},
                dataType: 'json',
                success: function (data) {
                    window.location.reload();
                    layer.msg(data.message);
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }

    function deliver_goods(obj, contract_number){
        layer.confirm('确认要设置为已发货吗？', function (index) {
            $.ajax({
                type: 'POST',
                url: '/bill/deliver',
                data: {contract_number: contract_number},
                dataType: 'json',
                success: function (data) {
                    layer.msg(data.message);
                    window.loaded.reload()
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }



</script>
